package cmd

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
)

var s string
var rootCmd = &cobra.Command{
	Use:   "eagle",
	Short: "eagle is a cobra example",
	PersistentPreRun: func(cmd *cobra.Command, agrs []string) {
		fmt.Println("PersistentPreRun")
	},
	PreRun: func(cmd *cobra.Command, args []string) {
		fmt.Println("PreRun")
	},
	PreRunE: func(cmd *cobra.Command, args []string) error {
		fmt.Println("PreRunE")
		return nil
	},
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("name is", s)
	},
	PostRun: func(cmd *cobra.Command, args []string) {
		fmt.Println("PostRun")
	},
	PersistentPostRun: func(cmd *cobra.Command, agrs []string) {
		fmt.Println("PersistentPostRun")
	},
}

func init() {
	// rootCmd.AddCommand()
	rootCmd.Flags().StringVarP(&s, "name", "n", "12", "a example")
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
